package com.ynet.middleground.user.service.impl;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.user.bean.GetChannelReq;
import com.ynet.middleground.user.common.ErrorMessageConstant;
import com.ynet.middleground.user.model.TheInternalManagementModel;
import com.ynet.middleground.user.service.TheInternalManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * @program: 2019-10-12_userCenter
 * @description: 内管系统服务实现类
 * @author: DaiGaoLe
 * @create: 2019-10-28 17:33
 **/
@Path("theInternal-management")
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8", MediaType.TEXT_XML + "; " + "charset=UTF-8"})
@Api(value = "内管系统服务实现类", tags = {"内管系统服务实现类"},hidden = true)
@Service(timeout = 6000, version = "0.0.1")
public class TheInternalManagementServiceImpl implements TheInternalManagementService, GenericService {

    @Autowired
    TheInternalManagementModel theInternalManagementModel;

    @POST
    @Path("channel")
    @ApiOperation(value = "获取渠道信息", notes = "获取渠道信息")
    @Override
    public ServiceResult<Map<String, String>> getChannel(GetChannelReq requestObject) {
        ServiceResult<Map<String, String>> resultService = new ServiceResult<>();
        Map<String, String> result = null;
        try {
            result = theInternalManagementModel.getChannelInfo(requestObject);
        } catch (BusinessException be) {
            resultService.setError(be.getCode(), be.getMessage());
            return resultService;
        } catch (Exception e) {
            // 获取当前方法名
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "case: {}",
                    Throwables.getStackTraceAsString(e));
            resultService.setError(ErrorMessageConstant.ECUC0000_CODE, ErrorMessageConstant.ECUC0000_MESSAGE);
            return resultService;
        }
        resultService.setResult(result);
        return resultService;

    }
}
